Skip to content

#408 - Regular expressions: validate the patterns with the configuration, throw on PCRE errors instead of "no match" - #409

Merged
njoubert-cleverage merged 3 commits into
mainfrom
408
Nov 3, 2026
Merged

njoubert-cleverage merged 3 commits into
mainfrom
408

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #408.

New internal Regex helper:

  • validate() compiles a pattern (preg_match($pattern, ''), the warning captured by a temporary error handler, the application handler restored) and throws an InvalidOptionsException naming the option and the PCRE error.
  • checkLastError() throws an UnexpectedValueException with preg_last_error_msg() when the last PCRE call has failed.

Used by:

  • preg_match (pattern): validated; a false result of preg_match() / preg_match_all() is checked.
  • preg_filter (pattern, string or list of strings): validated; a null result is checked, so "no match" still gives null.
  • slugify (replace): validated; a null result of preg_replace() is checked (it gave an empty slug).
  • the conditions (ConditionTrait: match_regexp, not_match_regexp of filter, column_aggregator, array_filter, unset): validated (a non-string pattern is rejected too); a false result is checked. Until now, it excluded the input with both options.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

None in the API. An invalid pattern now fails when the options are resolved, instead of filtering every input out (or a PHP warning, an exception in debug mode only). A PCRE error on a value now fails the transformer or task, instead of giving the "no match" result.

🤖 Generated with Claude Code

…ion, throw on PCRE errors instead of "no match"

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@njoubert-cleverage
njoubert-cleverage requested a review from a team as a code owner November 3, 2026 10:18
njoubert-cleverage and others added 2 commits November 3, 2026 11:23
…ends on the PHP version

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@njoubert-cleverage
njoubert-cleverage merged commit af6ba5d into main Nov 3, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regular expressions: PCRE errors taken for no match, invalid patterns only detected with the first value

1 participant